// compile: g++ -o constructor constructor.cc -std=c++14
// run: ./constructor
#include <iostream>

using namespace std;

class Base {
 public:
  // 默认构造函数
  Base() { cout << "Base::默认构造函数" << endl; }
  // 默认析构函数
  ~Base() { cout << "Base::默认析构函数" << endl; }
  // 拷贝构造函数
  Base(const Base&) { cout << "Base::拷贝构造函数" << endl; }
  // 拷贝赋值运算符
  Base& operator=(const Base& base) {
    cout << "Base::拷贝赋值运算符" << endl;
    this->data_ = base.GetData();
    return *this;
  }
  // 移动构造函数
  Base(Base&& base) { cout << "Base::移动构造函数" << endl; }
  // 移动赋值运算符
  Base& operator=(Base&& base) {
    cout << "Base::移动赋值运算符" << endl;
    this->data_ = base.GetData();
    return *this;
  }

  // 转换构造函数
  Base(int data) : data_(data) { cout << "Base::转换构造函数" << endl; }
  // 类型转换函数
  operator double() { return data_; }

  // 委托构造函数，这里的c无意义只是为了重载构造函数
  Base(int data, char c) : Base(data) { cout << "Base::委托构造函数" << endl; }

  int GetData() const { return data_; }

 private:
  int data_;
};
class Derived : public Base {
 public:
  // 继承构造函数
  using Base::Base;  // 直接使用基类的构造函数

 private:
};

void Test1() {
  Base base1;
  Base base2(base1);
  Base base3 = base2;  // 调用拷贝构造而不是拷贝赋值运算符
  base3 = base2;
  Base base4(std::move(base3));
  Base base5;
  base5 = std::move(base4);
  Base base6(5, 'c');

  double tmp = base6;
  cout << tmp << endl;
}
void Test2() {
  Derived d1(3);
  Derived d2(3, 'c');
}
int main() {
  Test1();
  Test2();
  return 0;
}
